package com.itany;

/**
 * Author：汤小洋
 * Date：2022-10-26 10:21
 * Description：<描述>
 */
public class Test03_Lambda表达式 {
    public static void main(String[] args) {
        Inter1 i = new Inter1() {
            @Override
            public int f1() {
                return 5;
            }
        };

        /**
         * Lambda表达式，用于简化匿名内部类的写法
         */
        Inter1 i1 = () -> 5;

        Inter2 i2 = m -> m * 2;

        Inter3 i3 = (m, n) -> m + n;

        Inter4 i4 = m -> System.out.print(m);

        Inter5 i5 = (m,n) -> {
            int sum = m + n;
            System.out.println(sum);
        };
    }
}

/**
 * 函数式接口：有且只有一个抽象方法
 */
interface Inter1 {
    int f1();
}

interface Inter2 {
    int f2(int m);
}

interface Inter3 {
    int f3(int m, int n);
}

interface Inter4 {
    void f4(String m);
}

interface Inter5 {
    void f5(int m, int n);
}